package com.wondertek.poms.search.listener;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.wondertek.poms.common.constant.Constants;
import com.wondertek.poms.dao.po.PrdCont;
import com.wondertek.poms.dao.repo.es.IPrdContESDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author evan0213
 * @description
 */
@Component
@Slf4j
public class PrdContListener {

	@Autowired
	private IPrdContESDao prdContESDao;

	@RabbitListener(queues = Constants.QUEUE_ES_PRD_CONT)
	public void receive(Message message) throws IOException {
		byte[] body = message.getBody();
		ObjectMapper mapper = new ObjectMapper();
		PrdCont prdCont = mapper.readValue(body, PrdCont.class);
		log.info("接收到mq消息|节目的id为：{}", prdCont.getPrdContId());
		prdContESDao.save(prdCont);
	}

}
